package cn.sunxyz.base.common;

/**
 * Created by yangrd on 2017/6/28.
 */
public class BoolPair extends Pair<Boolean, Boolean> {

    private static final BoolPair[][] boolPairsCache = new BoolPair[2][2];

    public static final BoolPair tt = _of(true, true);
    public static final BoolPair ff = _of(false, false);
    public static final BoolPair tf = _of(true, false);
    public static final BoolPair ft = _of(false, true);

    private BoolPair(Boolean first, Boolean last) {
        super(first, last);
    }


    public static BoolPair of(boolean t1, boolean t2) {
        return boolPairsCache[bool(t1)][bool(t2)];
    }

    private static BoolPair _of(boolean t1, boolean t2) {
        BoolPair boolPair = new BoolPair(t1, t2);
        boolPairsCache[bool(t1)][bool(t2)] = boolPair;
        return boolPair;
    }

    private static int bool(boolean t) {
        return t ? 1 : 0;
    }

    @Override
    public String toString() {
        return "BoolPair{" +
                "灯=" + (first ? "开" : "关") +
                '}';
    }
}
